#ifndef __DATE_H__
#define __DATE_H__

#include <iostream>
using namespace std;

class Date
{
	friend Date& operator+=(int day, Date& d);
	friend Date operator+(int day, const Date& d);

	friend Date& operator-=(int day, Date& d);
	friend Date operator-(int day, const Date& d);

	friend ostream& operator<<(ostream& out, const Date& d);
	friend istream& operator>>(istream& in, Date& d);
public:
	bool CheckDate() const;
	Date(int year = 1900, int month = 1, int day = 1);
	~Date();
	void Print() const;

	int GetMonthDay(int year, int month) const
	{
		static int day[] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };

		if (2 == month && ((0 == year % 4 && 0 != year % 100) || (0 == year % 400)))
			return day[month] + 1;

		return day[month];
	}

	Date(const Date& d);
	Date& operator=(const Date& d);

	Date* operator&()
	{
		return this;
	}

	const Date* operator&() const
	{
		return this;
	}

	Date& operator+=(int day);
	Date operator+(int day) const;

	Date& operator-=(int day);
	Date operator-(int day) const;

	Date& operator++();
	Date operator++(int);

	Date& operator--();
	Date operator--(int);

	int operator-(const Date& d) const;
	
	bool operator<(const Date& d) const;
	bool operator<=(const Date& d) const;
	bool operator>(const Date& d) const;
	bool operator>=(const Date& d) const;
	bool operator==(const Date& d) const;
	bool operator!=(const Date& d) const;

private:
	int _year;
	int _month;
	int _day;
};

ostream& operator<<(ostream& out, const Date& d);
istream& operator>>(istream& in, Date& d);

Date& operator+=(int day, Date& d);
Date operator+(int day, const Date& d);
Date& operator-=(int day, Date& d);
Date operator-(int day, const Date& d);

#endif

